//
//  ViewController.swift
//  alamofireTest
//
//  Created by apple on 2017/8/23.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //loadData()
        let url = "http://www.xftb168.com/welcome/getRecommended"
        let parameters = [
            "tokenid": "222",
            "platform":"1",
            "param": [
                "cityCode":"127",
                "latitude":"31.74593",
                "longitude":"117.287537"
            ]
            ] as [String : Any]

        HBJNetworkManager.shared.request(url: url, method: .post, paramters: parameters) { json,isSuccess in
            
            
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
extension ViewController{
    func loadData(){
        // Alamofire.NetworkReachabilityManager.ConnectionType
        let url = "http://www.xftb168.com/welcome/getRecommended"
        let parameters = [
            "tokenid": "222",
            "platform":"1",
            "param": [
                "cityCode":"127",
                "latitude":"31.74593",
                "longitude":"117.287537"
            ]
            ] as [String : Any]
       // Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: <#T##HTTPHeaders?#>)
        Alamofire.request(url, method: HTTPMethod.post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { (dataResponse) in
            print("POST_Request --> post 请求 --> returnResult = \(dataResponse)")
            
        }
    }
    func POST_Request(){
        
        
        //request(host_url, method:.post, parameters : parameters)
        
let urlstring = "http://www.xftb168.com/welcome/getRecommended"
        let parameters = [
            "tokenid": "222",
            "platform":"1",
            "param": [
                "cityCode":"127",
                "latitude":"31.74593",
                "longitude":"117.287537"
            ]
            ] as [String : Any]
        Alamofire.request(urlstring, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { (returnResult) in
                        print("POST_Request --> post 请求 --> returnResult = \(returnResult)")
            
                                    switch returnResult.result.isSuccess {
                                    case true:
                                   print("数据获取成功!")
                                   case false:
                                        print(returnResult.result.error ?? Error.self)
                                    }
        }

//        Alamofire.request(urlstring, method:.post,Parameters:parameters).responseJSON { (returnResult) in
//            print("POST_Request --> post 请求 --> returnResult = \(returnResult)")
//            //            switch returnResult.result.isSuccess {
//            //            case true:
//            //                print("数据获取成功!")
//            //            case false:
//            //                print(returnResult.result.error ?? Error.self)
//            //            }
//            
//        }
    }
    
   

}
